package cn.terminus.biz.customer.userrecordinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.userrecordinfo.dto.*;
import cn.terminus.data.customer.userrecordinfo.dao.UserRecordInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (UserRecordInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:19:10
 */
@Component
public class UserRecordInfoManager extends AbstractTerminusManager {
    @Autowired
    private UserRecordInfoDao userRecordInfoDao;

    public Integer add(UserRecordInfoNewDto dto) throws DataAccessException {
        try {
            return userRecordInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("UserRecordInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(UserRecordInfoEditDto dto) throws DataAccessException {
        try {
            return userRecordInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("UserRecordInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<UserRecordInfoResultDto> gets(UserRecordInfoGetsDto dto) throws DataAccessException {
        try {
            return userRecordInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("UserRecordInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<UserRecordInfoResultDto> query(UserRecordInfoQueryDto dto) throws DataAccessException {
        try {
            return userRecordInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("UserRecordInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(UserRecordInfoDeleteDto dto) throws DataAccessException {
        try {
            return userRecordInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("UserRecordInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<UserRecordInfoResultDto> page(UserRecordInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<UserRecordInfoResultDto> result = (Page<UserRecordInfoResultDto>) userRecordInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), UserRecordInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("UserRecordInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer addMulti(List<UserRecordInfoNewDto> list) throws DataAccessException {
        try {
            return userRecordInfoDao.addMulti(list);
        } catch (Exception e) {
            logger.error("CustomPurposeRoomManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

}
